package jp.dodododo.aop.util;

import java.util.Map;
import java.util.WeakHashMap;

import javassist.ClassPool;
import javassist.LoaderClassPath;
import jp.dodododo.aop.annotation.Enhance;

@Enhance(false)
public class ClassPoolUtil {

	private static Map<ClassLoader, ClassPool> instances = new WeakHashMap<ClassLoader, ClassPool>();

	public static ClassPool getClassPool(ClassLoader loader) {
		if (instances.containsKey(loader)) {
			return instances.get(loader);
		}
		ClassPool pool = new ClassPool();
		pool.appendClassPath(new LoaderClassPath(loader));
		instances.put(loader, pool);
		return pool;
	}
}
